﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using MillerApp.CommonLib.Utility;
using System.Reflection;
using System.Collections;
using Microsoft.International.Converters.PinYinConverter;


namespace MillerApp.Tools
{
    public class A
    {
        public string AString { get; set; }

        public A(string b)
        {
            AString = b;
        }
    }
    public class B
    {
        public List<A> ACollectionList { get; set; }
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //A a1 = new A("A1");
            //A a2 = new A("A2");
            //List<A> list = new List<A>();
            //list.Add(a1);
            //list.Add(a2);

            //B b = new B();
            //b.ACollectionList = list;

            //Type t = typeof(B);
            //PropertyInfo pInfo = t.GetProperty("ACollectionList");
            //object obj = pInfo.GetValue(b, null);
            //IEnumerable objlist = obj as IEnumerable;
            //foreach (var item in objlist)
            //{
            //    Type t2 = item.GetType();
            //    PropertyInfo pInfo2 = t2.GetProperty("AString");
            //    object obj2 = pInfo2.GetValue(item, null);
            //}

            //int dds = 1;

            dsfds();
            return;
        }

        public void dsfds()
        {
                       //CollectionHelper cHelper = new CollectionHelper();


            //List<TestClass> list = new List<TestClass>();
            //for (int i = 0; i < 10; i++)
            //{
            //    TestClass c = new TestClass();
            //    c.A = "string" + i.ToString();
            //    c.B = (decimal)(10 + i + 0.12);
            //    c.C = i;
            //    c.D = i % 2==0;
            //    list.Add(c);
            //}

            //DataTable dt = cHelper.ConvertTo<TestClass>(list);

            //List<TestClass> list2 = cHelper.ConvertToList<TestClass>(dt, new Dictionary<string, string>());

            //int b = 3;

            FileLog log = new FileLog("D:\\", "yyyyMMdd", "txt", false, long.MaxValue);

            //string texts = System.IO.File.ReadAllText(@"C:\Users\miller\AppData\Local\Tudou\iTudou\_35345149\TudouDownload\1.txt");
            string dirPath = @"C:\Users\miller\AppData\Local\Tudou\iTudou\_35345149\TudouDownload";
            //dirPath = @"H:\花鼓戏";
            string[] files = System.IO.Directory.GetFiles(dirPath);
            //int index = 131;

            List<string> names = new List<string>();

            foreach (string item in files)
            {
                try
                {
                   
                    string fileName3 = Path.GetFileName(item);

                    //if (fileName3.IndexOf("花鼓戏") < 0)
                    //{
                    //    continue;
                    //}


                    string fileName = fileName3;
                    //string cmpName = string.Empty;
                    //int lIndex = fileName.LastIndexOf(".");

                    //if (lIndex > 0)
                    //{
                    //    cmpName = fileName.Substring(0, lIndex - 1);
                    //}

                    fileName = fileName.Replace("湖南花鼓戏", string.Empty);
                    fileName = fileName.Replace("（流畅）", string.Empty);
                    fileName = fileName.Replace("（上集）", "（1集）");

                    //fileName = index.ToString() + fileName;

                    

                    //if (fileName.IndexOf("《") >= 0)
                    //{
                    //    char[] trimChar = { '《' };
                    //    string tempName = fileName.Trim(trimChar);
                    //    char first = tempName.ToCharArray().First<char>();
                    //    ChineseChar cnChar = new ChineseChar(first);
                    //    string number = cnChar.StrokeNumber.ToString();
                    //    number = number.PadLeft(3, '0');
                    //    //System.IO.File.Move(item, dirPath + "\\" +number+ fileName);
                    //}

                    if (fileName.IndexOf("Name")>= 0)
                    {
                        int a232 = 323;
                    }

                    char first = fileName.ToCharArray().First<char>();
                    bool isValidCChar = ChineseChar.IsValidChar(first);
                    if (isValidCChar == false)
                    {
                        continue;
                    }
                    ChineseChar cnChar = new ChineseChar(first);
                    string number = cnChar.StrokeNumber.ToString();
                    number = number.PadLeft(3, '0');

                   // int dsds3 = 0;
                    //
                    ////System.IO.File.Delete(item);
                    //index++;
                    names.Add(fileName3 + "    $   " + fileName);
                }
                catch { }
            }
            log.Write(names);
        }
    }
}
